<?php
require_once 'include.php';
require_once '_functions.php';

Connect();

$admin = mysql_fetch_assoc(getAdmin($_SESSION['adminId']));
var_dump($admin);
if (!$admin) {
	echo 'ERROR';
}

if (md5($_POST['oldpassword']) == $admin['password'] && $admin['email'] == $_POST['oldmail']) {
	if ($_POST['newpassword1'] == $_POST['newpassword2']) {
		if ($_POST['newpassword1'] == "") {
			$pass = null;
		} else {
			$pass = $_POST['newpassword1'];
		}
		
		editAdmin($_SESSION['adminId'],  $_POST['realname'], $_POST['email'], $pass);
		header('Location: index.php' ) ;
	} else {
		echo 'New passwords did not match.';
	}
} else {
	echo 'Invalid password. No changes was made.';
}
?>